//
//  CommonMethod.m
//  WMYRiceNoodles
//
//  Created by mac on 13-12-18.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "CommonMethod.h"

@implementation CommonMethod : NSObject

+ (void)closeKeyBoard {
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

+ (void)callPhone:(NSString *)phoneNumber superView:(UIView *)view
{
    UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectZero];
    NSURL *url = [NSURL URLWithString:[@"tel://" stringByAppendingString:phoneNumber]];
    [webview loadRequest:[NSURLRequest requestWithURL:url]];
    [view addSubview:webview];
}

+ (void)settingButton:(UIButton *)button
                Image:(NSString *)imageUrl
      hightLightImage:(NSString *)highLightImageUrl
         disableImage:(NSString *)disableImageUrl
{
    [button setImage:[UIImage imageNamed:imageUrl]
            forState:UIControlStateNormal];
    
    [button setImage:[UIImage imageNamed:highLightImageUrl]
            forState:UIControlStateHighlighted];
    
    [button setImage:[UIImage imageNamed:disableImageUrl]
            forState:UIControlStateDisabled];
}


+ (void)settingButton:(UIButton *)button
                Image:(NSString *)imageUrl
      hightLightImage:(NSString *)highLightImageUrl
{
    [button setImage:[UIImage imageNamed:imageUrl]
            forState:UIControlStateNormal];
    
    [button setImage:[UIImage imageNamed:highLightImageUrl]
            forState:UIControlStateHighlighted];
}


+ (void)settingButton:(UIButton *)button
                Image:(NSString *)imageUrl
        selectedImage:(NSString *)selectedImageUrl
{
    [button setImage:[UIImage imageNamed:imageUrl]
            forState:UIControlStateNormal];
    
    [button setImage:[UIImage imageNamed:selectedImageUrl]
            forState:UIControlStateSelected];
}


+ (void)hiddleExtendCellFromTableview:(UITableView *)tableview
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor clearColor];
    [tableview setTableFooterView:view];
}


+ (void)settingBackButtonImage:(NSString *)imagename andSelectedImage:(NSString *)selImagename
{
    UIImage* backImage = [[UIImage imageNamed:imagename]
                          resizableImageWithCapInsets:UIEdgeInsetsMake(30, 0, -30, 0)];
    
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImage
                                                      forState:UIControlStateNormal
                                                    barMetrics:UIBarMetricsDefaultPrompt];
    
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000)
                                                         forBarMetrics:UIBarMetricsDefault];
    
    
}



+ (void)settingBackButtonImage:(NSString *)imagename
                 selectedImage:(NSString *)selectedImagename
                  andContrller:(UIViewController *)controller
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:imagename]
            forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selectedImagename]
            forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(backToFather:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *mybuttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    controller.navigationItem.leftBarButtonItem = mybuttonItem;
}
+ (void)backToFather:(UIButton *)sender
{
    UINavigationBar *navigationBar = (UINavigationBar *)sender.superview;
    UINavigationController *nc = (UINavigationController *)[self GetViewController:navigationBar];
    [nc popViewControllerAnimated:YES];
}
+ (UIViewController*)GetViewController:(UIView*)uView
{
    for (UIView* next = [uView superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}


+ (CGFloat)checkSystemVersion
{
    static dispatch_once_t onceToken;
    __block float systemVersion = 0;
    dispatch_once(&onceToken, ^{
        systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    });
    return systemVersion;
}

+ (NSString *)checkAPPVersion
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
    NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
    
    return appVersion;
}



+ (NSString*)fuckNULL:(NSObject*)obj
{
    if (obj == nil || [obj isKindOfClass:[NSNull class]])
    {
        return @"";
        
    }else if ([obj isKindOfClass:[NSNumber class]])
    {
        return [NSString stringWithFormat:@"%@",obj];
        
    }else if(![obj isKindOfClass:[NSString class]])
    {
        return @"";
    }else if ([obj isKindOfClass:[NSString class]])
    {
        if ([(NSString *)obj isEqualToString:@"<null>"])
        {
            return @"";
            
        }else if ([(NSString *)obj isEqualToString:@"null"])
        {
            return @"";
        }else
        {
            return [NSString stringWithFormat:@"%@",obj];
        }
        
    }else
    {
        return @"";
    }
    
    
}


+(int)findStrIndex:(NSString *)findStr fromString:(NSString *)sourceStr
{
    NSRange range = [sourceStr rangeOfString:findStr];
    
    return (int)range.location;
}


+ (NSString *)getTimeNow
{
    NSString* date;
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    date = [formatter stringFromDate:[NSDate date]];
    NSString *timeNow = [[NSString alloc] initWithFormat:@"%@", date];
    
    return timeNow;
}


+ (NSString *)getTimeFromTimeInterval:(double)timeInterval
{
    
    NSString* date;
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
    
    [formatter setDateFormat:@"YYYY-MM-dd"];
    
    date = [formatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:timeInterval] ];
    
    NSString *timeAfter = [[NSString alloc] initWithFormat:@"%@", date];
    
    return timeAfter;
    
}

//  在 view 的指定位置加指定颜色的线
+ (UIView *) initLineInView:(UIView *)aView
                  withColor:(UIColor *)color
                   AndFrame:(CGRect)frame
{
    UIView * line = [[UIView alloc] init];
    line.backgroundColor = color;
    line.frame = frame;
    [aView addSubview:line];
    return line;
}


#pragma mark 匹配账户合法性(3_16位_字母数字和下划线的组合)

//验证用户输入不能为空
+(BOOL)checkUserInput:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
    
    int length = (int)[str stringByReplacingOccurrencesOfString:@" " withString:@""].length;
    
    if (length==0)
    {
        return NO;
    }
    
    return YES;
}

+ (BOOL)checkStringContainsEmoji:(NSString *)string
{
    __block BOOL returnValue = NO;
    
    [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                const unichar hs = [substring characterAtIndex:0];
                                if (0xd800 <= hs && hs <= 0xdbff) {
                                    if (substring.length > 1) {
                                        const unichar ls = [substring characterAtIndex:1];
                                        const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                                        if (0x1d000 <= uc && uc <= 0x1f77f) {
                                            returnValue = YES;
                                        }
                                    }
                                } else if (substring.length > 1) {
                                    const unichar ls = [substring characterAtIndex:1];
                                    if (ls == 0x20e3) {
                                        returnValue = YES;
                                    }
                                } else {
                                    if (0x2100 <= hs && hs <= 0x27ff) {
                                        returnValue = YES;
                                    } else if (0x2B05 <= hs && hs <= 0x2b07) {
                                        returnValue = YES;
                                    } else if (0x2934 <= hs && hs <= 0x2935) {
                                        returnValue = YES;
                                    } else if (0x3297 <= hs && hs <= 0x3299) {
                                        returnValue = YES;
                                    } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                                        returnValue = YES;
                                    }
                                }
                            }];
    
    return returnValue;
}
//验证用户名
+(BOOL)checkUserNameIsRight:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"^[a-zA-Z0-9_]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}
//验证老密码
+(BOOL)checkOLdPwdIsRight:(NSString *)str{
    if ([str length] == 0)
    {
        return NO;
    }
    NSString *regex = @"^[a-zA-Z0-9]{5,}$";
//    NSString *regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}

//验证登录界面密码
+(BOOL)checkPwdIsRight:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
//    NSString *regex = @"^[a-zA-Z][a-zA-Z0-9]{5,11}$";／／验证密码
    NSString *regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}

//验证其他修改密码界面
+(BOOL)checkPassWordIsRight:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
    //    NSString *regex = @"^[a-zA-Z][a-zA-Z0-9]{5,11}$";／／验证密码
    NSString *regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}
//验证一卡通
+(BOOL)checkOneCardWithRegex:(NSString *)OneCard
{
    if ([OneCard length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"[0-9]{13,15}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:OneCard];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
    
}
//验证数字
+(BOOL)checkNumbersWithRegex:(NSString *)num
{
    if ([num length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"^[0-9]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:num];

    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
    
}
//验证金额
+(BOOL)checkMoneyWithRegex:(NSString *)num
{
    if ([num length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"^[0-9.]*$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:num];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
    
}

//验证验证码格式
+(BOOL)checkVerifyCode:(NSString *)verifyCode
{
    if ([verifyCode length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"[0-9]{6}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:verifyCode];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
    
}

//验证QQ
+ (BOOL)checkQQ:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"[0-9]{4,15}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}

//验证手机格式
+ (BOOL)checkTel:(NSString *)str
{
    if ([str length] == 0)
    {
        return NO;
    }
    
    NSString *regex = @"^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch)
    {
        return NO;
    }
    
    return YES;
}

//验证邮箱
+(BOOL)checkEmailWithRegex:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}








//滑动到最后一行
+(void)scrollTableToFootWithTableView:(UITableView *) tableView isAnimated:(BOOL)animated
{
    NSInteger s = [tableView numberOfSections];
    if (s<1) return;
    NSInteger r = [tableView numberOfRowsInSection:s-1];
    if (r<1) return;
    
    NSIndexPath *ip = [NSIndexPath indexPathForRow:r-1 inSection:s-1];
    
    [tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:animated];
}


+(void)setCornerRadius:(CGFloat)radius borderColor:(UIColor *)color ForView:(UIView *)aview
{
    
    aview.layer.cornerRadius = radius;
    aview.layer.borderColor = [color CGColor];
    
    if (radius > 0)
    {
        aview.layer.masksToBounds = YES;
        aview.layer.borderWidth = 1;
    }
    else
    {
        aview.layer.masksToBounds = NO;
        aview.layer.borderWidth = 0;
    }
}


+ (NSInteger)ChineseNumberInString:(NSString *)str
{
    int j = 0 ;
    
    for(int i = 0; i < [str length]; i++)
    {
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff)
            j++;
    }
    return j;
}

+(void)cleanSubViewsInSuperView:(UIView *)superView
{
    
    //依次遍历self.view中的所有子视图
    for(id tmpView in superView.subviews)
    {
        //找到要删除的子视图的对象
        if([tmpView isKindOfClass:[UIView class]])
        {
            [tmpView removeFromSuperview];
        }
    }
    
    
}



//单个文件的大小
+ (long long) fileSizeAtPath:(NSString*) filePath
{
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath])
    {
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
    }
    return 0;
}


//遍历文件夹获得文件夹大小，返回多少M
+ (float ) folderSizeAtPath:(NSString*) folderPath
{
    NSFileManager* manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]) return 0;
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString* fileName;
    long long folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil)
    {
        NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        folderSize += [self fileSizeAtPath:fileAbsolutePath];
    }
    return folderSize/(1024.0*1024.0);
}




//消息推送是否开启
+ (BOOL)isAllowedNotification
{
    //iOS8 check if user allow notification
//    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0f)
//    {// system is iOS8
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types)
        {
            return YES;
        }
//    }
//    else
//    {//iOS7
//        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
//        if(UIRemoteNotificationTypeNone != type)
//            return YES;
//    }
    return NO;
}

+(NSString *)starForTel:(NSString *)tel
{
    //新建一个字符串
    NSString *star = @"****";
    NSString *prefix = [tel substringToIndex:3];
    NSString *suffix = [tel substringFromIndex:7];
    NSString *starTel = [NSString stringWithFormat:@"%@%@%@",prefix,star,suffix];
    
    return starTel;
    
}

+(CGFloat)heightForLabel:(UILabel *)label
                WithText:(NSString *)text
                fontName:(NSString *)fontName
                fontSize:(CGFloat)fontSize
                   width:(CGFloat)width
{
    if (!text)
    {
        return 0;
    }else
    {
        if (!fontName)
        {
            //系统默认的字体
            fontName = @"Helvetica";
        }
        
        //创建字体信息
        UIFont *textFont = [UIFont fontWithName:fontName size:fontSize];
        //字体字典信息
        NSDictionary *fontDict =[NSDictionary dictionaryWithObject:textFont forKey:NSFontAttributeName];
        
        //设置label的属性
        label.frame = CGRectMake(width/2, 0, width, 0);
        label.numberOfLines = 0 ;
        label.lineBreakMode = NSLineBreakByCharWrapping;
        label.backgroundColor = [UIColor clearColor];
        label.font = textFont;
        
        
        CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
                                         options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                      attributes:fontDict
                                         context:nil];
        
        return rect.size.height+10;
        
    }
    
}



/**
 *  背景视图
 */
+(void)checkBackgroudViewForBaseView:(UIView *)baseView withArr:(NSArray *)arr
{
    if (arr.count != 0)
    {
        [self deleteBackgroundViewForBaseView:baseView];
    }else
    {
        [self addBackgroundViewForBaseView:baseView];
    }
}

+(void)addBackgroundViewForBaseView:(UIView *)baseView
{
    
    UIView *view = [baseView viewWithTag:9999];
    
    if (!view)
    {
        UIImageView *backImageView = [[UIImageView alloc] initWithFrame:baseView.frame];
        backImageView.contentMode = UIViewContentModeScaleAspectFit ;
        backImageView.image = [UIImage imageNamed:@"nodata"];
        backImageView.tag = 9999;
        [baseView addSubview:backImageView];
    }
    
}
+ (void)addBackgroundViewForBaseView:(UIView *)baseView imageName:(NSString *)imageName {
    UIView *view = [baseView viewWithTag:9999];
    
    if (!view)
    {
        UIImageView *backImageView = [[UIImageView alloc] initWithFrame:baseView.frame];
        backImageView.contentMode = UIViewContentModeScaleAspectFit ;
        backImageView.image = [UIImage imageNamed:imageName];
        backImageView.tag = 9999;
        [baseView addSubview:backImageView];
    }
}

+(void)deleteBackgroundViewForBaseView:(UIView *)baseView
{
    UIView *view = [baseView viewWithTag:9999];
    
    if (view)
    {
        [view removeFromSuperview];
    }
}


+ (UIImage *)watermarkImage:(UIImage *)img text:(NSString *)str {
    
    //    1、获取图片
    //    UIImage *image = [UIImage imageNamed:@"icon_takePhoto"];
    //    2、获取位图上下文
    UIGraphicsBeginImageContext(CGSizeMake(img.size.width,img.size.height));
    //    3、绘制图片
    [img drawAtPoint:CGPointMake(0, 0)];
    //    4、绘制文字
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    
    NSString *strDate = [formatter stringFromDate:date];
    [strDate drawAtPoint:CGPointMake(img.size.width * 0.05 , img.size.height * 0.9) withAttributes:@{NSForegroundColorAttributeName:[UIColor brownColor],NSFontAttributeName:[UIFont systemFontOfSize:200],NSBackgroundColorAttributeName:[UIColor whiteColor]}];
    //    [strDate drawInRect:CGRectMake(0, img.size.height-50, img.size.width * 2, 30) withAttributes:@{NSForegroundColorAttributeName:[UIColor brownColor],NSFontAttributeName:[UIFont systemFontOfSize:22],NSBackgroundColorAttributeName:[UIColor whiteColor]}];
    //    5、生成图片
    img = UIGraphicsGetImageFromCurrentImageContext();
    //    6、关闭上下文
    UIGraphicsEndImageContext();
    //    7、获取图片数据
    //    NSData *data = UIImagePNGRepresentation(image);
    //    8、保存图片
    //    self.imageView.image = [UIImage imageWithData:data];
    
    return img;
}


+ (NSString *)stringWithUserLevel:(NSString *)str {
    if ([str isEqualToString:@"0"]) {
        return @"普通会员";
    }
    if ([str isEqualToString:@"2"]) {
        return @"初级消费顾问";
    }
    if ([str isEqualToString:@"4"]) {
        return @"高级消费顾问";
    }
    if ([str isEqualToString:@"6"]) {
        return @"主管";
    }
    if ([str isEqualToString:@"8"]) {
        return @"经理";
    }
    if ([str isEqualToString:@"10"]) {
        return @"总监";
    }
    if ([str isEqualToString:@"12"]) {
        return @"CEO";
    }
    return nil;
}

+ (void)setImageViewLayer:(UIImageView *)img {
    img.layer.masksToBounds = YES;
    img.layer.borderWidth = 1.0f;
    img.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2f].CGColor;
    img.layer.cornerRadius = 8.0f;
}


+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

+ (NSString *)achieveDateStringBy_yyyy_MM_dd_WithNow  {
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter stringFromDate:date];
}

+ (NSString *)achieveDateStringBy_yyyy_MM_dd_HH_mm_ss_WithNow  {
    NSDate *date = [NSDate dateWithTimeInterval:3600*8 sinceDate:[NSDate date]];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:date];
}


+ (NSString *)achieveDateStringBy_yyyy_MM_dd_WithDate:(NSDate *)date  {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter stringFromDate:date];
}

+ (NSString *)achieveDateStringBy_yyyy_MM_dd_HH_mm_ss_WithDate:(NSDate *)date  {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    return [formatter stringFromDate:date];

}

+ (NSString *)getNowDateValue {
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"yyyyMMdd"];
    return [formatter stringFromDate:date];
}

+ (BOOL)TodayHasBeenOperatingWithUserdefaultsKey:(NSString *)key {
    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    if (str.length > 0) {
        NSString *now = [self getNowDateValue];
        if (now.integerValue > str.integerValue) {
            return false;
        }else{
            return true;
        }
    }else {
        return false;
    }
}



@end
